<template>
    <div>
        <h2>医生列表</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                   <td>Id</td>
                   <td>医生名称</td>
                   <td>头像</td>
                   <td>科室</td>
                   <td>创建时间</td>
                </tr>
                 <tr v-for="item in data.list">
                   <td>{{ item.Id }}</td>
                   <td>{{ item.SirName }}</td>
                   <td>
                    <img :src="item.pic" width="60" height="60" alt="">
                   </td>
                   <td>{{ item.KeName }}</td>
                   <td>{{ moment(item.CreateTime).format("YYYY-MM-DD") }}</td>
                </tr>
            </tbody>
        </table>
        <div>
            <span>共{{ data.totelcount }}条</span>
            <span>每页{{ info.pagesize }}条</span>
            <span>当前{{ info.pageindex }}/{{ data.totelpage }}页</span>
            <input type="button" value="首页" class="btn btn-primary" @click="togo(1)"></input>
            <input type="button" value="上一页" class="btn btn-primary" @click="togo(info.pageindex-1)"></input>
            <input type="button" value="下一页" class="btn btn-primary" @click="togo(info.pageindex+1)"></input>
            <input type="button" value="尾页" class="btn btn-primary" @click="togo(data.totelpage)"></input>
        </div>
    </div>
</template>

<script setup lang="ts">
import axios from "axios";
import moment from "moment";
import {ref,reactive,onMounted} from "vue"
import {useRoute,useRouter} from "vue-router"
import {useStore} from "@/stores/user"

const route = useRoute();
const router = useRouter();
const abc = useStore();


let info:any = reactive({
    pageindex:1,
    pagesize:3
})

let data:any = reactive({
    list:[],
    totelcount:0,
    totelpage:0
})

onMounted(()=>{
    if(abc.userinfo.Id){
        getSir();
    }
    else{
        router.push('/login')
    }
})

const togo=(num:any)=>{
    if(num<1){
        info.pageindex=1;
        return;
    }
    if(num>data.totelpage){
        info.pageindex=data.totelpage;
        return;
    }
    info.pageindex=num;
    getSir();
}

//医生信息
const getSir=()=>{
    axios({
        url:'/api/YeHotels/GetSir',
        method:'get',
        params:info
    })
    .then(res=>{
        console.log(res);
        Object.assign(data,res.data)
    })
    .catch(err=>{
        console.log(err);
        
    })
}

</script>

<style scoped>
span{
    margin: 0 5px;
}
input{
    margin: 0 5px;
}
</style>